<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="_path" value="${pageContext.request.contextPath}"></c:set>
<form id="queryAabForm" style="margin:10;text-align: center;">
	<table width="100%">
		<tr>
			<td>商户ID：</td>
			<td>
				<input class="easyui-numberbox" name="id" style="width: 200"/>
			</td>
			<td>商户名称(简)：</td>
			<td>
				<input name="namesimp" style="width: 200"/>
			</td>
			<td align="center">
				<a href="javascript:void(0);" onclick="clearForm()" class="easyui-linkbutton" iconCls="icon-search">清空</a>
			</td>
		</tr>
		<tr>
			<td>登记日期：</td>
			<td>
				<input class="easyui-datebox" name="creatdate" style="width: 200"/>
			</td>
			<td>负责人移动电话：</td>
			<td>
				<input name="telephone" style="width: 200">
			</td>
			<td align="center"><a href="javascript:void(0);" onClick="doSearch()" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
		</tr>
	</table>
</form>
<div id="aabTable"></div>
<script>

function returnListJson(val){
	var jsonList = '${ json.aab}';
	jsonList = eval('('+jsonList+')');
	return jsonList[val];
}
jQuery(function($){
	$('#aabTable').datagrid({
		title:'商户列表',//标题
		method:'post',
		iconCls:'icon-edit',//图标
		singleSelect:false,//多选
		height:400, //高度
		fitColumns: true,//自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。
		striped: true,//奇偶行颜色不同
		collapsible:false,//可折叠
		sortName: 'id', //排序的列
		sortOrder: 'desc', //倒序
		remoteSort: true, //服务器端排序
		idField:'id', //主键字段
		queryParams:{}, //查询条件
		pagination:true, //显示分页
		rownumbers:true, //显示行号
		columns:[[
			{field:'ck',checkbox:true,width:2}, //显示复选框
			{field:'id',title:'商户ID',width:20,sortable:true},
			{field:'namesimp',title:'商户名称(简)',width:20,sortable:true},
			{field:'nameall',title:'商户名称(全)',width:20,sortable:true},
			{field:'selltaxtype',title:'手续费支付模式',width:20,sortable:true,
				formatter:function(value,row,index){return returnListJson(row.selltaxtype);}},
			{field:'selltax',title:'手续费率',width:20,sortable:true},
			{field:'creatdate',title:'登记日期',width:20,sortable:true},
			{field:'telephone',title:'负责人移动电话',width:20,sortable:true}
		]],
		toolbar:[{
			text:'新增',
			iconCls:'icon-add',
			handler:function(){
				addrow();
			}
		},'-',{
			text:'更新',
			iconCls:'icon-edit',
			handler:function(){
				updaterow();
			}
		},'-',{
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				deleterow();
			}
		},'-'],
		onLoadSuccess:function(){
			$('#aabTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
		}
	});
	doSearch();
});
//新增
function addrow(){
	showWindow({
			title:'增加商户信息',
			href:'${_path}/aab/aabAddWindow',
			width:500,
			height:450
		});
}
function updaterow(){
	var rows = $('#aabTable').datagrid('getSelections');
	//这里有一个jquery easyui datagrid的一个小bug，必须把主键单独列出来，要不然不能多选
	if(rows.length==0){
		$.messager.alert('提示',"请选择你要更新的商户",'info');
		return;
	}
	if(rows.length > 1){
		$.messager.alert('提示',"只能选择一位商户进行更新",'info');
		return;
	}
	showWindow({
			title:'更新商户信息',
			href:'${_path}/aab/aabUpdateWindow?id='+ rows[0].id,
			width:500,
			height:450
		});
}
//删除
function deleterow(){
	var rows = $('#aabTable').datagrid('getSelections');
	if(rows.length == 0){
		$.messager.alert('提示',"请选择你要删除的商户",'info');
		return;
	}
	$.messager.confirm('提示','确定要删除吗?',function(result){
		if (result){
			var ps = "";
			$.each(rows,function(i,n){
				if(i==0) 
					ps += "?json=[{'id':"+n.id+",'version':"+n.version+"}";
				else
					ps += ",{'id':"+n.id+",'version':"+n.version+"}";
			});
			ps=ps+"]";
			$.post('${_path}/aab/delete'+ps,function(data){
				$('#aabTable').datagrid('reload'); 
				$.messager.alert('提示',data.mes,'info');
			});
		}
	});
}
//表格查询
function doSearch(){
	var params = $('#aabTable').datagrid('options').queryParams;//先取得 datagrid的查询参数
	var fields =$('#queryAabForm').serializeArray();//自动序列化表单元素为JSON对象
	$.each( fields, function(i, field){
		params[field.name] = field.value;//设置查询参数
	}); 
	$('#aabTable').datagrid({url:"aab/queryList"});
}
//清空查询条件
function clearForm(){
	$('#queryAabForm').form('clear');
	doSearch();
}
</script>